package com.feib.soeasy.service.impl;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.feib.soeasy.dao.PaymentDao;
import com.feib.soeasy.dao.PaymentItemDao;
import com.feib.soeasy.model.PaymentItem;
import com.feib.soeasy.pagination.ItemGroupListBean;
import com.feib.soeasy.pagination.PaginatedList;
import com.feib.soeasy.service.PaymentItemService;

/**
 * @title (#)PaymentServiceItemImpl.java<br>
 * @description 繳費單項目邏輯物件<br>
 * @author Leo Lee<br>
 * @version 1.0.0 2010/11/26
 * @copyright Far Eastern International Bank Copyright (c) 2010<br>
 * @2010/11/26 create by Leo Lee<br>
 */
@Service("paymentItemService")
public class PaymentItemServiceImpl extends BaseServiceImpl implements PaymentItemService {

    @Resource(name="paymentItemDao")
    private PaymentItemDao paymentItemDao;

    /**
     * 繳費項目分類群組總覽
     * @param uploadFilePk uploadFilePk
     * @return 查詢結果物件
     */
    @Override
    public PaginatedList<ItemGroupListBean> queryPaymentItemGroupByUploadFilePk(
                    Long uploadFilePk) {
        List list = paymentItemDao.queryPaymentItemGroupByUploadFilePk(uploadFilePk);

        PaginatedList<ItemGroupListBean> paginatedList = 
            new PaginatedList<ItemGroupListBean>();

        if(null != list)
        {
            List<ItemGroupListBean> itemList = new ArrayList<ItemGroupListBean>() ;
            for(Iterator i=list.iterator();i.hasNext();)
            {
                ItemGroupListBean item = new ItemGroupListBean();
                Object[] row = (Object[]) i.next();
                item.setItemName(String.valueOf(row[0]));
                item.setItemAmounts(new Long(String.valueOf(row[1])));
                item.setItemCounts(new Long(String.valueOf(row[2])));
                itemList.add(item);
            }
            paginatedList.setPaginatedList(itemList);
        }


        return paginatedList;
    }

}
